<!--
 * @Author: Olivia
 * @Date: 2023-02-26 20:52:03
 * @custom_string_Olivia: Less is more
-->
<template>
    <div>
        <van-picker title="请选择性别" :default-index="gender" show-toolbar :columns="genderData" @confirm="onConfirm"
            @cancel="$emit('close')" @change="onChange" />
    </div>
</template>
<script>
import { updateName } from '@/api/user'
export default {
    name: 'UpdateGender',

    data() {
        return {
            gender: this.value,
            genderData: ['男', '女']

        }
    },
    props: {
        value: {
            type: Number,
            required: true
        }
    },
    created() {
        console.log(this.value);
    },
    computed: {
    },
    methods: {
        async onConfirm() {
            try {
                this.$toast.loading({
                    messege: '完成中',
                    forbidClick: true,
                    duration: 0 //持续展示toast
                })
                await updateName({
                    gender: this.gender
                })
                // 1-更新视图 2-关闭弹出层 3-提示成功
                this.$emit('input', this.gender)
                this.$emit('close')
                this.$toast('修改成功')
            } catch (error) {
                this.$toast('修改性别失败', error)
            }
        },
        onChange(picker, value, index) {
            this.gender = index
        }
    }
}
</script>
<style lang='less'  scoped></style>
